Skip to content

Conversation

@Shubbu03
Copy link

@Shubbu03 Shubbu03 commented Dec 2, 2025

Summary

This PR adds the Magic Router–specific RPC methods to the ephemeral validator so that the existing Connection/ConnectionMagicRouter client code can be reused against a validator endpoint.

Changes

Extend JsonRpcHttpMethod and HttpDispatcher to support:

  • getRoutes
  • getBlockhashForAccounts
  • getDelegationStatus

Implement validator-side handlers:

  • getRoutes: returns [] (validator is not a router; API compatibility only).
  • getBlockhashForAccounts: aliases getLatestBlockhash, ignoring params (single validator - blockhash source).
  • getDelegationStatus: returns { isDelegated: boolean } based on AccountSharedData::delegated() in AccountsDb, without resolving delegation records.

Fixes #658

Summary by CodeRabbit

  • New Features
    • Added getDelegationStatus RPC — returns an isDelegated boolean for an account.
    • Added getRoutes RPC for route information (mocked to return an empty list).
    • Added getBlockhashForAccounts RPC support.
    • These methods are available over both HTTP and WebSocket JSON‑RPC transports.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

Adds support for three Magic Router JSON-RPC methods: getRoutes, getBlockhashForAccounts, and getDelegationStatus. New enum variants were added for both HTTP and WebSocket methods. A new HTTP handler get_delegation_status was added to HttpDispatcher; it parses a single Pubkey parameter, fetches the local account, extracts an isDelegated boolean, and returns a JSON payload { "isDelegated": bool }. The HTTP dispatcher routing was updated to call the new handlers, and a mocked get_routes handler returning an empty list was added.

Suggested reviewers

  • thlorenz
  • lucacillario

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed PR implements all three required RPC methods (getRoutes, getBlockhashForAccounts, getDelegationStatus) with appropriate validator-side handlers matching the issue requirements.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the three magic router-compatible RPC methods specified in issue #658; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2be43c5 and 9adb9c6.

📒 Files selected for processing (6)
  • magicblock-aperture/src/requests/http/get_blockhash_for_accounts.rs (1 hunks)
  • magicblock-aperture/src/requests/http/get_delegation_status.rs (1 hunks)
  • magicblock-aperture/src/requests/http/get_routes.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mod.rs (1 hunks)
  • magicblock-aperture/src/requests/mod.rs (2 hunks)
  • magicblock-aperture/src/server/http/dispatch.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/http/get_program_accounts.rs:17-25
Timestamp: 2025-10-21T13:06:38.900Z
Learning: The magicblock validator does not support ledger forking, so commitment-based state queries (processed/confirmed/finalized) are not applicable. RPC methods can safely ignore commitment and minContextSlot parameters from Solana RPC config objects.
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-aperture/src/requests/http/mod.rs
  • magicblock-aperture/src/requests/mod.rs
🧬 Code graph analysis (1)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
magicblock-aperture/src/requests/mod.rs (1)
  • params (27-31)
🔇 Additional comments (8)
magicblock-aperture/src/server/http/dispatch.rs (1)

229-231: LGTM!

The routing for the three new Magic Router compatibility methods follows the established pattern. The sync/async distinction is appropriate: GetRoutes and GetBlockhashForAccounts are synchronous since they don't perform I/O, while GetDelegationStatus is correctly awaited as it calls read_account_with_ensure.

magicblock-aperture/src/requests/http/mod.rs (1)

305-309: LGTM!

The module declarations are well-organized with a clear comment indicating their purpose. Grouping the Magic Router compatibility methods separately improves discoverability.

magicblock-aperture/src/requests/http/get_blockhash_for_accounts.rs (1)

1-17: LGTM!

The implementation correctly aliases getLatestBlockhash for API compatibility. The docstring clearly explains that this is an intentional simplification for the validator context (single blockhash source). Based on learnings, the magicblock validator doesn't support ledger forking, so returning the latest blockhash is the appropriate behavior.

magicblock-aperture/src/requests/http/get_routes.rs (1)

1-15: LGTM!

The implementation correctly returns an empty routes list for API compatibility, as a validator is not a router. The docstring clearly documents this intentional behavior.

magicblock-aperture/src/requests/http/get_delegation_status.rs (1)

28-38: LGTM!

The account retrieval and delegation status derivation logic is correct. Using unwrap_or(false) for non-existent accounts is appropriate—an account that doesn't exist cannot be delegated. The response payload format matches the documented API contract.

magicblock-aperture/src/requests/mod.rs (3)

80-85: LGTM! Well-documented enum additions.

The three new HTTP method variants are clearly documented with accurate descriptions of their validator-side behavior. The comments correctly indicate that:

  • GetRoutes is mocked (returns empty array for compatibility)
  • GetBlockhashForAccounts aliases the existing getLatestBlockhash
  • GetDelegationStatus exposes a simple delegation flag

149-151: LGTM! String mappings are correct.

The string mappings correctly use camelCase convention and match the method names expected by the Magic Router SDK.


91-102: AI summary is inaccurate: WebSocket variants were not added despite claims.

The AI summary states that GetRoutes, GetBlockhashForAccounts, and GetDelegationStatus were added to JsonRpcWsMethod, but the diff shows no changes to this enum. Only HTTP variants were added.

If WebSocket support is required for these methods (for Magic Router or other clients), the corresponding JsonRpcWsMethod variants and handlers must be added.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd990cd and c107fbd.

📒 Files selected for processing (4)
  • magicblock-aperture/src/requests/http/get_delegation_status.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mocked.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mod.rs (1 hunks)
  • magicblock-aperture/src/server/http/dispatch.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/http/get_program_accounts.rs:17-25
Timestamp: 2025-10-21T13:06:38.900Z
Learning: The magicblock validator does not support ledger forking, so commitment-based state queries (processed/confirmed/finalized) are not applicable. RPC methods can safely ignore commitment and minContextSlot parameters from Solana RPC config objects.
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-aperture/src/requests/http/mod.rs
  • magicblock-aperture/src/requests/http/get_delegation_status.rs
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
🧬 Code graph analysis (3)
magicblock-aperture/src/requests/http/mod.rs (1)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
  • get_delegation_status (12-30)
magicblock-aperture/src/requests/http/mocked.rs (1)
magicblock-aperture/src/requests/payload.rs (2)
  • encode_no_context (85-100)
  • encode_no_context (138-148)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
magicblock-aperture/src/requests/mod.rs (1)
  • params (27-31)
🔇 Additional comments (3)
magicblock-aperture/src/requests/http/mod.rs (1)

305-307: Module wiring for get_delegation_status looks consistent

The new module export and Router-compatibility comment align with existing handler organization and keep router-specific logic clearly separated.

magicblock-aperture/src/requests/http/get_delegation_status.rs (1)

1-31: get_delegation_status handler is concise and reuses existing helpers appropriately

The handler cleanly uses parse_params!/some_or_err!, read_account_with_ensure, and AccountSharedData::delegated() to derive a minimal { "isDelegated": bool } response, defaulting safely to false when the account is absent or cannot be ensured. This matches the “validator-only, no router-style resolution” design.

Please just confirm that the Magic Router SDK / client code treats any extra fields as optional and is happy with this minimal object shape.

magicblock-aperture/src/server/http/dispatch.rs (1)

229-233: Verify getBlockhashForAccounts param compatibility with get_latest_blockhash

The routing directly delegates GetBlockhashForAccounts to get_latest_blockhash(request) without visible param transformation. Confirm that get_latest_blockhash accepts the param shape sent by Magic Router SDK's getBlockhashForAccounts calls (which likely differ from standard getLatestBlockhash params). If param shapes are incompatible, add normalization before delegation to achieve the intended drop-in compatibility.

@bmuddha
Copy link
Collaborator

bmuddha commented Dec 19, 2025

@Shubbu03 thanks for addressing the comments. Can you please resolve the issues with the CI and we can merge this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c1b9a2 and 5549072.

📒 Files selected for processing (2)
  • magicblock-aperture/src/requests/http/get_delegation_status.rs (1 hunks)
  • magicblock-aperture/src/requests/http/mocked.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/http/get_program_accounts.rs:17-25
Timestamp: 2025-10-21T13:06:38.900Z
Learning: The magicblock validator does not support ledger forking, so commitment-based state queries (processed/confirmed/finalized) are not applicable. RPC methods can safely ignore commitment and minContextSlot parameters from Solana RPC config objects.
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
  • magicblock-aperture/src/requests/http/mocked.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
  • magicblock-aperture/src/requests/http/mocked.rs
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.

Applied to files:

  • magicblock-aperture/src/requests/http/get_delegation_status.rs
🧬 Code graph analysis (1)
magicblock-aperture/src/requests/http/get_delegation_status.rs (1)
magicblock-aperture/src/requests/mod.rs (1)
  • params (27-31)
🔇 Additional comments (5)
magicblock-aperture/src/requests/http/get_delegation_status.rs (5)

1-2: LGTM!

Standard prelude import pattern consistent with other handlers in the codebase.


3-15: LGTM! Clear documentation of simplified validator behavior.

The documentation appropriately clarifies that this is a simplified implementation that returns only the isDelegated boolean flag without resolving delegation records. This aligns with the PR objectives for validator-specific behavior that differs from the full Magic Router implementation.


16-19: LGTM! Proper use of helper macros.

The parameter parsing correctly uses parse_params! and some_or_err! macros, following the pattern established in get_account_info as requested in the previous review feedback.


28-30: LGTM!

Clean response construction using the json! macro and appropriate encoding method.


21-26: No changes needed. The code correctly implements the intended behavior.

The read_account_with_ensure method's side effect of fetching accounts from the reference cluster is explicitly intentional, as documented in the function's comment (lines 21-22) and the method documentation in get_account_info.rs. This pattern is consistently used across multiple RPC endpoints (get_balance, get_account_info, get_token_account_balance) to ensure clients receive current state by populating the local AccountsDb from the reference cluster when needed. The error handling strategy properly logs failures and continues with available data, matching project patterns.

Likely an incorrect or invalid review comment.

@Shubbu03
Copy link
Author

@bmuddha i've pushed code to fix it, after running locally, but the 1st action - add-deploy-comment fails with 403, so i'm not getting how to fix this

@Shubbu03 Shubbu03 requested a review from thlorenz as a code owner December 20, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement handling of RPC methods that magic router uses

2 participants